<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script>

description("This tests the constructor for the MediaStreamEvent DOM class.");

var testObject = {nyannyan: 123};
var mediaStream = new MediaStream();

// No initializer is passed.
shouldBe("new MediaStreamEvent('eventType').bubbles", "false");
shouldBe("new MediaStreamEvent('eventType').cancelable", "false");
shouldBe("new MediaStreamEvent('eventType').stream", "null");

// bubbles is passed.
shouldBe("new MediaStreamEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new MediaStreamEvent('eventType', { bubbles: true }).bubbles", "true");

// cancelable is passed.
shouldBe("new MediaStreamEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new MediaStreamEvent('eventType', { cancelable: true }).cancelable", "true");

// stream is passed.
// Valid object.
shouldBe("new MediaStreamEvent('eventType', { stream: mediaStream }).stream", "mediaStream");

// Invalid objects.
shouldThrow("new MediaStreamEvent('eventType', { stream: testObject }).stream");
shouldThrow("new MediaStreamEvent('eventType', { stream: document }).stream");
shouldBe("new MediaStreamEvent('eventType', { stream: undefined }).stream", "null");
shouldBe("new MediaStreamEvent('eventType', { stream: null }).stream", "null");
shouldThrow("new MediaStreamEvent('eventType', { stream: false }).stream");
shouldThrow("new MediaStreamEvent('eventType', { stream: true }).stream");
shouldThrow("new MediaStreamEvent('eventType', { stream: '' }).stream");
shouldThrow("new MediaStreamEvent('eventType', { stream: 'chocolate' }).stream");
shouldThrow("new MediaStreamEvent('eventType', { stream: 12345 }).stream");
shouldThrow("new MediaStreamEvent('eventType', { stream: 18446744073709551615 }).stream");
shouldThrow("new MediaStreamEvent('eventType', { stream: NaN }).stream");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrow("new MediaStreamEvent('eventType', { stream: {valueOf: function () { return mediaStream; } } }).stream == mediaStream");
shouldBe("new MediaStreamEvent('eventType', { get stream() { return mediaStream; } }).stream", "mediaStream");
shouldThrow("new MediaStreamEvent('eventType', { get stream() { return 123; } }).stream");
shouldThrow("new MediaStreamEvent('eventType', { get stream() { throw 'MediaStreamEvent Error'; } })");

// All initializers are passed.
shouldBe("new MediaStreamEvent('eventType', { bubbles: true, cancelable: true, stream: mediaStream }).bubbles", "true");
shouldBe("new MediaStreamEvent('eventType', { bubbles: true, cancelable: true, stream: mediaStream }).cancelable", "true");
shouldBe("new MediaStreamEvent('eventType', { bubbles: true, cancelable: true, stream: mediaStream }).stream", "mediaStream");
</script>
</body>
</html>
